// packageB/pages/jihuo/index.js
const common = require('../../../public.js')
const city = require('./citys')
// const citys = require('./city')
Page({
    /**
     * 页面的初始数据
     */
    data: {

        status: "9",
        files: [
            {
                url: 'https://img.yzcdn.cn/vant/leaf.jpg',
                name: '图片1',
            },
            // Uploader 根据文件后缀来判断是否为图片文件
            // 如果图片 URL 中不包含类型信息，可以添加 isImage 标记来声明
            {
                url: 'http://iph.href.lu/60x60?text=default',
                name: '图片2',
                isImage: true,
                deletable: true,
            },
        ],
        fileList: [], //发票照片
        shows: false, //控制下拉列表的显示隐藏，false隐藏、true显示
        selectDatas: [
            // '再生资源回收点', '家政服务点', '综合超市', '生鲜超市', '邮政快递综合服务点', '维修点', '照相文印店', '美容美发店'
        ], //下拉列表的数据
        indexs: 0, //选择的下拉
        username: '', //姓名
        cardNum: '', //身份证号
        phone: "", //手机号
        userId: "", //用户
        product: "", //购买产品
        invoiceNo: "", //发票
        invoiceCode: "", //发票代码
        checkCode: '', //校验码
        noDuesPrice: "",
        oldToNew: false, // 是否以旧换新,0：是，1：否
        areaFlag: false,
        minHour: 10,
        maxHour: 20,
        date: '',
        managerId: "",
        captchaId: 'fb6455d8a495496f8780b3c0aed5ea85',
        // minDate: new Date().getTime(),
        // maxDate: new Date(2022, 10, 1).getTime(),
        startDate: '',
        endDate: "",
        currentDate: new Date().getTime(),
        // areaList:  city.region,
        address: "选择城市",
        // regionStateId: "", //省
        regionCityId: "", //市
        // regionDistrictId: "", //区
        receiverAddress: "", //详细地址
        invoicePrice: "",
        day: "",
        region: '',
        fileListtwo: [],
        fileListthree: [],
        baseUrl: 'https://api.feiyanghy.com',
        cityss: [],
        multiSelector: [],
        //根据索引查找
        customIndex: [0, 0, 0], //以下是城市三级联动国标code
        list: [],
        product: ["电视", "冰箱", "洗衣机", "空调", "燃气灶", "抽油烟机", "手机", "电脑（包含平板电脑"],
        productText: '',
        isShowCity: "",
        proviceArrayss: [
            [],
            [],
            []
        ],
        proviceArray: [
            [],
            [],
            []
        ],
        onlyArray: [
            [],
            [],
            []
        ],
        storeText: '',
        placeText: '',
        radio: '0', //1代表普票 0专
        ra: 1,
        icon: {
            normal: 'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/icon/vip-bill.png',
            active: 'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/icon/vip-function.png',
        },
        tengZhou: [], //滕州券集合
        adminCouponNos: [], //后台要的所选中的所有券
        nowTime: 0,
        identityCardFrontList: [],  //身份证正面
        identityCardBackList: [],//身份证背面
        drivingLicenseListzhu: [], //行驶证主页
        drivingLicenseListfu: [], //行驶证副业
        drivingLicenseListDeng: [], //机动车登记证

        accountsBank: '', //开户行
        bankAccount: '', //银行账号
        idCardShowFlag: false, //身份证照片
        invoiceShowFlag: false,
        imgList: [], //实例图片
        imgArrTwo: [],
        titlePic: '',
        addlll: '',
        bankKey: '', //关键词
        regionCityIds: '',
        bankIndex: -1,
        bankShow: false,
        bankList: [],
        bankCode: '',
        feiPayOne: [undefined, undefined, undefined], //飞羊支付凭证
        shopPayList: [], //购物车凭证
        shopPayListOther: [],
        shopPayListThree: [],
        checkedImgNone: 'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/icon/checkedNon.png',
        checkedImgDui: 'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/icon/checkedDui.png',
        multiArray: [
            [],
            [],


        ],
        city,
        provice: [],
        cityId: -1,  //城市码
        proviceName: '',
        isRequest: true
    },
    //点击确定按钮
    // bindRegionChange: function (e) {
    //     console.log(e.detail.value)
    //     console.log(e.detail.code)
    //     this.setData({
    //         region: e.detail.value
    //     })
    // },
    // 上下滑动
    bindMultiPickerColumnChange(e) {
        let index = e.detail.value
        let column = e.detail.column
        let arrCity = []
        if (!column) {
            let cityes = this.data.city.city[index].children
            for (let i = 0; i < cityes.length; i++) {
                arrCity.push(cityes[i].label)
            }
            let arrfff = [this.data.provice, arrCity]
            this.data.multiArray[1] = arrCity
            this.setData({
                multiArray: arrfff
            })
        }
    },
    // 确定
    bindMultiPickerChange(e) {
        let arrIndex = e.detail.value
        let cityes = this.data.city.city[arrIndex[0]].children[arrIndex[1]]

        this.setData({
            regionCityIds: cityes.value,
            proviceName: this.data.city.city[arrIndex[0]].label,
            cityName: cityes.label
        })

    },
    // 身份证
    click_shili() {
        let identityCardFrontList = [
            'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/coup/idCardFront.png',
            'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/coup/idCardBack.png'
        ]
        let titlePic = '身份证正反面'
        this.setData({
            titlePic,
            idCardShowFlag: true,
            imgList: identityCardFrontList
        })

    },


    // 城市列表
    getCityList() {
        common.post('/region/getCitys', {}, (res) => {
            if (res.status === 200) {
                this.setData({
                    cityss: res.data
                }, () => {
                    this.initPickerData() //日期三联动
                })
            } else {

            }
        })
    },

    click_driving() {
        let identityCardFrontList = [
            'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/coup/drivingOne.png',
            'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/coup/drivingTwo.png'
        ]
        let titlePic = '行驶证'
        this.setData({
            titlePic,
            idCardShowFlag: true,
            imgList: identityCardFrontList
        })
    },
    // 发票实例
    click_invoice() {
        let identityCardFrontList = [
            'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/coup/invoiceCoup.png'
        ]
        let titlePic = '发票照片'
        this.setData({
            imgArrTwo: identityCardFrontList,
            titlePic,
            invoiceShowFlag: true
        })
    },
    // 支付凭证
    click_payOrder() {
        let identityCardFrontList = [
            'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/coup/payOrder.png'
        ]
        let titlePic = '支付凭证'
        this.setData({
            imgArrTwo: identityCardFrontList,
            titlePic,
            invoiceShowFlag: true
        })
    },
    click_car() {
        let identityCardFrontList = [
            'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/coup/drivingLicense.png'
        ]
        let titlePic = '机动车登记证第一二页'
        this.setData({
            imgArrTwo: identityCardFrontList,
            titlePic,
            invoiceShowFlag: true
        })
    },
    idCardShow() {
        this.setData({
            idCardShowFlag: false
        })
    },
    // 发票
    closeInvoice() {
        this.setData({
            invoiceShowFlag: false
        })
    },

    // 发票金额不含税
    onnoDuesPrice(e) {
        this.setData({
            noDuesPrice: e.detail,
        });
    },
    //校验码
    oncheckCode(e) {
        this.setData({
            checkCode: e.detail,
        });
    },
    //发票代码
    oninvoiceCode(e) {
        // console.log( e.detail,"444444555")
        this.setData({
            invoiceCode: e.detail,
        });
    },
    // 发票选择
    onChangeInvoice(event) {
        console.log(event.detail, "1111")
        this.setData({
            radio: event.detail,
        });
    },

    bindPickerChange(e) {
        console.log(e, "444444")
        var index = e.detail.value
        this.setData({
            productText: this.data.product[index]
        })
    },

    afterRead(event) {
        var that = this
        const {
            file
        } = event.detail;
        console.log(file)
        // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
        wx.uploadFile({
            url: common.HttpUrl + '/uploadOldToNewImage', //仅为示例，非真实的接口地址
            filePath: file.url,
            header: {
                "Content-Type": "multipart/form-data"
            },
            name: 'filename', //这个是
            formData: {
                filename: file.url
            },
            success(res) {
                const data = JSON.parse(res.data)
                var arr = []
                arr.push({
                    url: data.data[0],
                    deletable: true,
                })
                that.setData({
                    fileList: arr
                })
            }
        })
    },

    // 初始化网点picker数据
    initPickerData() {
        let list = this.data.cityss
        let {
            proviceArray,
            customIndex,
            onlyArray
        } = this.data
        let data = {
            proviceArray,
            list,
            customIndex,
            onlyArray
        }

        for (let i = 0; i < data.list.length; i++) {
            // console.log(data.list[i].value, "54159695")
            data.onlyArray[0].push(data.list[i].label) //省
            data.proviceArray[0].push({
                provicename: data.list[i].label,
                value: data.list[i].value
            })
        }
        for (let j = 0; j < data.list[data.customIndex[0]].children.length; j++) { //城市
            console.log(data.list[data.customIndex[0]].children[j].label)
            data.onlyArray[1].push(data.list[data.customIndex[0]].children[j].label)

        }
        for (let k = 0; k < data.list[data.customIndex[0]].children[data.customIndex[1]].children.length; k++) { //区

            data.onlyArray[2].push(data.list[data.customIndex[0]].children[data.customIndex[1]].children[k].label)

        }

        this.setData(data)
        if (this.data.status == 7) {
            this.getCheckCoupon()
        }

    },
    dele(e) {
        console.log(e.detail.file.url)
        e.detail.file.url = ""
        // this.data.fileList[0].url =""
        this.setData({
            fileList: []
        })
    },
    // 飞羊支付凭证
    deles(e) {
        console.log(e)
        const that = this
        let index = e.currentTarget.dataset.index
        e.detail.file.url = ""
        this.setData({
            fileListtwo: []
        })

        this.data.feiPayOne.splice(index, 1, undefined);
        console.log(this.data.feiPayOne, "54444444444444444444444444444444")
        this.setData({
            feiPayOne: this.data.feiPayOne
        }, () => {
            let ffff = that.isUndefined(that.data.feiPayOne)
            console.log(ffff)
            that.setData({
                ffff
            })
            console.log(this.data.feiPayOne, "00000000000000000000000000")
        })
    },
    delesfour(e) {
        const that = this
        console.log(e.detail)
        let index = e.currentTarget.dataset.index
        e.detail.file.url = ""
        this.data.shopPayListOther.pop()
        // this.data.fileList[0].url =""
        this.setData({
            shopPayListOther: this.data.shopPayListOther
        })
        // delete this.data.feiPayOne[index];
        this.data.feiPayOne.pop()
        this.setData({
            feiPayOne: this.data.feiPayOne
        }, () => {
            let ffff = that.isUndefined(that.data.feiPayOne)
            console.log(ffff)
            that.setData({
                ffff
            })
            console.log(this.data.feiPayOne, "00000000000000000000000000")
        })
    },
    // 购物车付款截图
    delestwo(e) {
        const that = this
        console.log(e.detail)
        let index = e.currentTarget.dataset.index
        e.detail.file.url = ""
        // this.data.fileList[0].url =""
        this.setData({
            shopPayList: []
        })
        // delete this.data.feiPayOne[index];
        this.data.feiPayOne.splice(index, 1, undefined);
        this.setData({
            feiPayOne: this.data.feiPayOne
        }, () => {
            let ffff = that.isUndefined(that.data.feiPayOne)
            console.log(ffff)
            that.setData({
                ffff
            })
            console.log(this.data.feiPayOne, "00000000000000000000000000")
        })
    },
    // 购物车截图
    delesThree(e) {
        const that = this
        // 替换元素 替换起始下标为2，长度为1的一个值为‘hh’，len设置的1
        // arr.splice(2, 1, 'hh');

        let index = e.currentTarget.dataset.index
        e.detail.file.url = ""
        // this.data.fileList[0].url =""
        this.setData({
            shopPayListThree: []
        })
        // delete this.data.feiPayOne[index];

        this.data.feiPayOne.splice(index, 1, undefined);

        this.setData({
            feiPayOne: this.data.feiPayOne
        }, () => {
            console.log(this.data.feiPayOne, "00000000000000000000000000")
            let ffff = that.isUndefined(this.data.feiPayOne)
            that.setData({
                ffff
            })
            console.log(ffff)
        })

    },

    isUndefined(arr) {
        console.log(this.data.shopPayListOther)
        let isUndefined = true;
        for (let i = 0; i < arr.length; i++) {
            console.log(this.data.feiPayOne[i], "222245555")
            if (!arr[i] && this.data.shopPayListOther.length == 0) {
                isUndefined = false
            }
        }
        return isUndefined
    },

    identityCardFrontClose(e) {
        e.detail.file.url = ""
        // this.data.fileList[0].url =""
        this.setData({
            identityCardFrontList: []
        })
    },
    identityCardBackClose(e) {
        e.detail.file.url = ""
        // this.data.fileList[0].url =""
        this.setData({
            identityCardBackList: []
        })
    },
    drivingLicenseclosezhu(e) {
        e.detail.file.url = ""
        // this.data.fileList[0].url =""
        this.setData({
            drivingLicenseListzhu: []
        })
    },
    drivingLicenseclosefu(e) {
        e.detail.file.url = ""
        // this.data.fileList[0].url =""
        this.setData({
            drivingLicenseListfu: []
        })
    },
    drivingLicenseDengClose(e) {
        e.detail.file.url = ""
        // this.data.fileList[0].url =""
        this.setData({
            drivingLicenseListDeng: []
        })
    },
    //点击picker确定按钮时触发 
    bindCustomPickerChange(e) {
        // console.log("chufa")
        let {
            proviceArray,
            list,
            customIndex,
            onlyArray
        } = this.data
        this.setData({
            // regionStateId: list[customIndex[0]].value,
            regionCityId: list[customIndex[0]].children[customIndex[1]].value,
            // regionDistrictId: list[customIndex[0]].children[customIndex[1]].children[customIndex[2]].value
        })
        //这里的三层for循环是为了取出最底层数组中的站点id传给后台
        for (let x = 0; x < list.length; x++) {
            for (let y = 0; y < list[x].children.length; y++) {
                for (let z = 0; z < list[x].children[y].children.length; z++) {
                    console.log(list[x].children[y].children[e.detail.value[2]].value)
                    this.siteId = list[x].children[y].children[e.detail.value[2]].value
                }
            }
        }
        // console.log(onlyArray[0][customIndex[0]])
        this.setData({
            customIndex: e.detail.value,
            placeText: `${onlyArray[0][customIndex[0]]}-${onlyArray[1][customIndex[1]]}-${onlyArray[2][customIndex[2]]}`
        })
    },

    //列改变时触发
    bindCustomPickerColumnChange(e) {
        let {
            proviceArray,
            list,
            customIndex,
            onlyArray
        } = this.data
        customIndex[e.detail.column] = e.detail.value
        //更新数据
        const searchColumn = () => {
            console.log(e)
            for (let i = 0; i < list.length; i++) {
                let arr1 = []
                let arr2 = []
                console.log(e)
                console.log(customIndex[0])
                if (i === customIndex[0]) {
                    for (let j = 0; j < list[i].children.length; j++) {
                        console.log(list[i])
                        arr1.push(list[i].children[j].label)
                        if (j === customIndex[1]) {
                            for (let k = 0; k < list[i].children[j].children.length; k++) {
                                arr2.push(list[i].children[j].children[k].label)
                            }
                            onlyArray[2] = arr2
                        }
                    }
                    onlyArray[1] = arr1
                }
            }
        }
        switch (e.detail.column) {
            case 0:
                customIndex[1] = 0
                customIndex[2] = 0
                searchColumn()
                break;
            case 1:
                customIndex[2] = 0
                searchColumn()
                break
        }
        this.setData({
            onlyArray: onlyArray,
            customIndex: customIndex
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */

    onoldToNew(e) {
        console.log(e.detail)
        this.setData({
            oldToNew: e.detail,
        });
    },
    onareaFlag(e) {
        this.setData({
            areaFlag: e.detail, //true是选中
        }, () => {

            //  console.log(this.data.adminCouponNos,"this.data.adminCouponNos")
        });
    },
    onInput(event) {
        this.setData({
            currentDate: event.detail,
        });
    },
    // 点击下拉显示框
    selectTaps(e) {
        console.log(e, "wwwww")
        this.setData({
            shows: !this.data.shows,
        });
    },
    // 点击下拉列表
    optionTaps(e) {
        let Indexs = e.currentTarget.dataset.index; //获取点击的下拉列表的下标
        console.log(Indexs)
        console.log(this.data.selectDatas[Indexs], "qqqqq")
        this.setData({
            indexs: Indexs,
            shows: !this.data.shows
        });
    },

    shopPayOther(event) {
        var that = this
        const {
            file
        } = event.detail;
        console.log(file, "45454444")
        // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
        wx.uploadFile({
            url: common.HttpUrl + '/uploadPayImage', //仅为示例，非真实的接口地址
            filePath: file.url,
            header: {
                "Content-Type": "multipart/form-data"
            },
            name: 'filename', //这个是
            formData: {
                filename: file.url
            },
            success(res) {
                const data = JSON.parse(res.data)
                console.log(data, "5555")
                // var arr = []
                that.data.shopPayListOther.push(
                    {
                        url: data.data[0],
                        deletable: true,
                    }
                )
                that.data.feiPayOne.push(
                    data.data[0]
                )

                that.setData({
                    feiPayOne: that.data.feiPayOne,
                    shopPayListOther: that.data.shopPayListOther
                })

            }
        })
    },
    shopPayThree(event) {
        var that = this
        const {
            file
        } = event.detail;

        let index = event.currentTarget.dataset.index
        console.log(file, "45454444")
        // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
        wx.uploadFile({
            url: common.HttpUrl + '/uploadPayImage', //仅为示例，非真实的接口地址
            filePath: file.url,
            header: {
                "Content-Type": "multipart/form-data"
            },
            name: 'filename', //这个是
            formData: {
                filename: file.url
            },
            success(res) {
                const data = JSON.parse(res.data)
                console.log(data, "5555")
                // var arr = []
                // that.data.shopPayListThree.push(
                //     {
                //         url: data.data[0],
                //         deletable: true,
                //     }
                // )
                that.data.shopPayListThree = [{
                    url: data.data[0],
                    deletable: true,
                }]


                that.data.feiPayOne[index] = data.data[0]

                console.log(that.data.feiPayOne, "that.data.fileListtwo")
                console.log(that.data.shopPayList, "that.data.shopPayLists")
                that.setData({
                    feiPayOne: that.data.feiPayOne,
                    shopPayListThree: that.data.shopPayListThree
                }, () => {
                    let ffff = that.isUndefined(that.data.feiPayOne)
                    that.setData({
                        ffff
                    })
                    console.log(ffff)
                })

            }
        })
    },
    shopPay(event) {
        var that = this
        console.log(event, "444444776655")
        let index = event.currentTarget.dataset.index
        const {
            file
        } = event.detail;
        console.log(file, "45454444")
        // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
        wx.uploadFile({
            url: common.HttpUrl + '/uploadPayImage', //仅为示例，非真实的接口地址
            filePath: file.url,
            header: {
                "Content-Type": "multipart/form-data"
            },
            name: 'filename', //这个是
            formData: {
                filename: file.url
            },
            success(res) {
                const data = JSON.parse(res.data)
                console.log(data, "5555")
                // var arr = []
                that.data.shopPayList = [{
                    url: data.data[0],
                    deletable: true,
                }]

                that.data.feiPayOne[index] = data.data[0]

                console.log(that.data.feiPayOne, "that.data.fileListtwo")
                that.setData({
                    feiPayOne: that.data.feiPayOne,
                    shopPayList: that.data.shopPayList
                }, () => {
                    console.log(that.data.feiPayOne, "that.data.fileListtwo")
                    let ffff = that.isUndefined(that.data.feiPayOne)
                    that.setData({
                        ffff
                    })
                    console.log(ffff)
                })

            }
        })
    },
    afterReadtwo(event) {
        var that = this
        console.log(event, "444444776655")
        let index = event.currentTarget.dataset.index
        const {
            file
        } = event.detail;
        console.log(file, "45454444")
        // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
        wx.uploadFile({
            url: common.HttpUrl + '/uploadPayImage', //仅为示例，非真实的接口地址
            filePath: file.url,
            header: {
                "Content-Type": "multipart/form-data"
            },
            name: 'filename', //这个是
            formData: {
                filename: file.url
            },
            success(res) {
                const data = JSON.parse(res.data)
                console.log(data, "5555")
                // var arr = []
                that.data.fileListtwo.push(
                    {
                        url: data.data[0],
                        deletable: true,
                    }
                )
                that.data.feiPayOne[0] = data.data[0]
                console.log(that.data.feiPayOne, "that.data.fileListtwo")
                that.setData({
                    feiPayOne: that.data.feiPayOne,
                    fileListtwo: that.data.fileListtwo
                }, () => {
                    var ffff = that.isUndefined(that.data.feiPayOne)
                    console.log(ffff)
                    that.setData({
                        ffff
                    })

                })

            }
        })
    },
    // 身份证前面
    identityCardFront(event) {
        const that = this
        this.picUpload(event).then((r, j) => {
            console.log(r, "000uhhhhhh")
            var arr = []
            arr.push({
                url: r,
                deletable: true,
            })
            that.setData({
                identityCardFrontList: arr
            }, () => {
                console.log(that.data.identityCardFrontList, "全面审查费错错错错错错")
            })
        })

    },
    picUpload(event) {
        var that = this
        const {
            file
        } = event.detail;
        return new Promise((ress, rej) => {
            // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
            wx.uploadFile({
                url: common.HttpUrl + '/adminCouponCon/apps/qualification/uploadPic',
                filePath: file.url,
                header: {
                    "Content-Type": "multipart/form-data"
                },
                name: 'filename', //这个是
                formData: {
                    filename: file.url
                },
                success(res) {
                    const data = JSON.parse(res.data)
                    ress(data.data)
                }
            })
        })

    },
    // 身份证背面
    identityCardBack(event) {
        const that = this
        this.picUpload(event).then((r, j) => {

            var arr = []
            arr.push({
                url: r,
                deletable: true,
            })
            that.setData({
                identityCardBackList: arr
            }, () => {
                console.log(that.data.identityCardFrontList, "背面错错错错错错")
            })
        })
    },
    // 行驶证主页
    drivingLicensezhu(event) {
        const that = this
        this.picUpload(event).then((r, j) => {
            var arr = []
            arr.push({
                url: r,
                deletable: true,
            })
            that.setData({
                drivingLicenseListzhu: arr
            }, () => {
                console.log(that.data.drivingLicenseListzhu, "机动车错错错错错错")
            })
        })

    },
    // 行驶证 副业
    drivingLicensefu(event) {
        console.log(event, "行驶证第二页99999")
        const that = this
        this.picUpload(event).then((r, j) => {

            var arr = []
            arr.push({
                url: r,
                deletable: true,
            })
            that.setData({
                drivingLicenseListfu: arr
            }, () => {
                console.log(that.data.drivingLicenseListfu, "行驶证副页错错错错错错")
            })
        })
    },
    // 机动车登机车
    drivingLicenseDeng(event) {

        const that = this
        this.picUpload(event).then((r, j) => {
            console.log(r, "000uhhhhhh")
            var arr = []
            arr.push({
                url: r,
                deletable: true,
            })
            that.setData({
                drivingLicenseListDeng: arr
            }, () => {
                console.log(that.data.drivingLicenseListDeng, "行驶证副页错错错错错错")
            })
        })
    },
    // 以旧换新凭证
    afterReadthree(event) {
        var that = this
        const {
            file
        } = event.detail;
        console.log(file)
        // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
        wx.uploadFile({
            url: common.HttpUrl + '/uploadOldToNewImage', //仅为示例，非真实的接口地址
            filePath: file.url,
            header: {
                "Content-Type": "multipart/form-data"
            },
            name: 'filename', //这个是
            formData: {
                filename: file.url
            },
            success(res) {
                const data = JSON.parse(res.data)
                var arr = []
                arr.push({
                    url: data.data[0],
                    deletable: true,
                })
                that.setData({
                    fileListthree: arr
                })
            }
        })
    },
    // 开户行名称
    inputAccountsBank(e) {
        this.setData({
            accountsBank: e.detail
        })
    },
    // 银行账号
    inputBankAccount(e) {
        this.setData({
            bankAccount: e.detail
        })
    },
    // 提交
    // submit: common.throttleFunc(function (e) { //限制重复点击
    submit() {

        if (!this.data.storeText) {
            common.showToast('购买门店不能为空')
        } else
            if (!this.data.identityCardFrontList[0]) {
                common.showToast('请上传身份证正面')
            } else
                if (!this.data.identityCardBackList[0]) {
                    common.showToast('请上传身份证背面')
                } else
                    if (!this.data.drivingLicenseListzhu[0]) {
                        common.showToast('请上传行驶证主页')
                    } else
                        if (!this.data.drivingLicenseListfu[0]) {
                            common.showToast('请上传行驶证副页')
                        } else
                            if (!this.data.drivingLicenseListDeng[0]) {
                                common.showToast('请上传机动车登记证')
                            } else

                                if (this.data.radio == 1) {   //普票
                                    console.log("普票")
                                    if (!this.data.invoicePrice) {
                                        common.showToast('发票金额不能为空')
                                    } else if (!this.data.invoiceCode) {
                                        common.showToast('发票代码不能为空')
                                    } else if (!this.data.invoiceNo) {
                                        common.showToast('发票号码不能为空')
                                    } else if (!this.data.date) {
                                        common.showToast('开票日期不能为空')
                                    } else if (!this.data.checkCode) {
                                        common.showToast('校验码不能为空')
                                    } else {
                                       
                                        this.toTalFn()
                                    }
                                } else if (this.data.radio == 0) {  //专票
                                    console.log("专票")
                                    if (!this.data.invoicePrice) {
                                        common.showToast('发票金额不能为空')
                                    } else if (!this.data.noDuesPrice) {
                                        common.showToast('不含税金额不能为空')
                                    } else if (!this.data.invoiceCode) {
                                        common.showToast('发票代码不能为空')
                                    } else if (!this.data.invoiceNo) {
                                        common.showToast('发票号码不能为空')
                                    } else if (!this.data.date) {
                                        common.showToast('开票日期不能为空')
                                    } else {
                                      
                                        this.toTalFn()
                                    }
                                }

    },
    // 共用的校验

    toTalFn() {
        if (!this.data.fileList[0]) {
            common.showToast('请上传发票照片')
        } else if (!this.data.fileListtwo[0]) {
            common.showToast('支付凭证第一张不能为空')
        } else if (!this.data.accountsBank) {
            common.showToast('开户行不能为空')
        } else if (!this.data.bankAccount) {
            common.showToast('银行账号不能为空')
        } else if (!this.data.bankCode) {
            common.showToast('银行行号不能为空')
        } else {
            this.ji_huo()
        }
    },
    fnss() {
        var that = this
        // this.selectComponent('#captcha').popup() //验证码登录
        if (this.data.areaFlag) {
            // 把上个页面的券放进去
            for (var i = 0; i < this.data.tengZhou.length; i++) {
                this.data.adminCouponNos.push(this.data.tengZhou[i].couponNo)
            }
        } else {
            this.data.adminCouponNos = [this.data.adminCouponNo]
        }
        this.setData({
            adminCouponNos: this.data.adminCouponNos
        }, () => {
            this.ji_huo()
        })

    },
    ji_huo: common.throttleFunc(function (e) {
        console.log("cehsichei")
        var that = this
        let newArr = []
        that.setData({
            isRequest: false
        })
        for (let i = 0; i < this.data.feiPayOne.length; i++) {
            if (this.data.feiPayOne[i] !== undefined) {
                newArr.push(this.data.feiPayOne[i])
            }
        }
        let url = '/adminCouponCon/apps/qualification/checkInfoSubmit'
        let params = {
            noDuesPrice: this.data.noDuesPrice ? this.data.noDuesPrice : "", //不含税金额   
            couponNo: this.data.adminCouponNos[0],
            userId: that.data.userId,
            storeId: this.data.arrTwo[this.data.indexs].id,
            receiveUsername: that.data.userInfo.username,
            receiveIdcard: that.data.cardNum,
            receviePhone: that.data.phone,
            idcardFrontPic: this.data.identityCardFrontList[0].url,
            idcardBackPic: this.data.identityCardBackList[0].url,
            driveLicensePic: this.data.drivingLicenseListzhu[0].url,
            driveLicensePicSubpage: this.data.drivingLicenseListfu[0].url,
            // 行驶证----------------
            motorRegistrationPic: this.data.drivingLicenseListDeng[0].url,
            userBankNo: this.data.bankAccount,
            userBankName: this.data.accountsBank,
            userBankUsername: this.data.username,
            invoiceType: this.data.radio, //发票类型，0：专票，1：普票
            invoicePrice: this.data.invoicePrice, //发票金额
            invoiceCode: this.data.invoiceCode,
            invoiceNo: this.data.invoiceNo, //发票号码
            checkCode: this.data.checkCode, //发票校验码
            buyTime: this.data.date,
            invoiceUrl: this.data.fileList[0].url,
            payImageUrl: '',  //支付凭证
            userBankCode: this.data.bankCode,
            payimagesList: newArr.toString()

        }

        common.post(url, params, function (res) {
            if (res.status === 200) {
                common.showToast(res.msg)
                wx.redirectTo({
                    url: '/pages/cultureCoupons/myCultureCoupons/index',
                })
            } else {
                //    加载完毕
                that.setData({
                    isRequest: true
                })
                common.showRequestErrMsg(res)
            }
        }, () => {

        })
    }, 6000),
    // 获取门店列表
    storeList() {
        var that = this
        var url = '/discountCoupon/getScanStoreListByManagerId'
        var params = {
            managerId: this.data.managerId
        }
        common.post(url, params, function (res) {
            if (res.status === 200) {
                that.setData({
                    arrTwo: res.data
                }, () => {
                    that.storeFn()
                })
            } else {
                common.showRequestErrMsg(res)
            }
        })
    },
    // 下拉选择地区
    bindRegionChange: function (e) {
        console.log(e)
        let that = this
        const codeList = e.detail.code
        this.setData({
            // regionStateId: codeList[0],
            // regionCityIds: codeList[1],
            // regionDistrictId: codeList[2]
        })
        const valueList = e.detail.value
        let valueName = []
        valueList.map(i => {
            valueName.push(i)
        })
        this.setData({
            addlll: valueName.join('-'),
        }, () => {

        })
    },
    // 输入关键词
    inputBankKey(e) {
        // console.log(e,"77445555")
        this.setData({
            bankKey: e.detail.value,  //开票日期
        });
    },
    // 选择下拉日期
    bindDateChange: function (e) {
        // 日期
        console.log(e)
        this.setData({
            date: e.detail.value,  //开票日期
            day: e.detail.value.substring(8, 10)
        });
    },

    onProduct(e) {
        console.log(e.detail);
        this.setData({
            product: e.detail
        })
    },
    oninvoicePrice(e) {
        this.setData({
            invoicePrice: e.detail
        })
    },
    oninvoiceNo(e) {
        this.setData({
            invoiceNo: e.detail
        })
    },
    onAddress: function (e) {
        this.setData({
            receiverAddress: e.detail
        })
    },
    search_btn() {
        // console.log(this.data.regionCityIds.substring(0, 4))
        // console.log(this.data.bankKey, "55555")
        if (!this.data.regionCityIds) {
            common.showToast('城市不能为空')
            return
        } else if (!this.data.bankKey) {
            common.showToast('请输入银行名称或者银行行号')
            return
        }
        this.getBank()
    },
    // 银行列表
    getBank() {
        let temp = {
            areaCode: this.data.regionCityIds,
            key: this.data.bankKey
        }
        common.post('/store/getBankInfoOnChinaums', temp, (res) => {
            if (res.status === 200) {
                console.log(res.data, "00000000000000000000")
                let bankList = JSON.parse(res.data)
                console.log(bankList)
                this.setData({
                    // cityss: res.data
                    bankList
                }, () => {
                    this.setData({
                        bankShow: true
                    })
                })
            } else {

            }
        })
    },
    choiceBank(e) {

        let item = e.currentTarget.dataset.item
        let obj = e.currentTarget.dataset
        this.setData({
            bankIndex: obj.index,
            bankItem: obj,
            bankCode: item.code,
            accountsBank: item.bankBranchName

        }, () => {
            console.log(this.data.accountsBank, "iiiiiii")

        })
    },
    // 银行确定
    submit_bank() {
        console.log(this.data.bankItem)
        if (!this.data.bankItem && this.data.bankList.length !== 0) {
            common.showToast('请选择银行')
            return
        }
        this.setData({
            bankShow: false
        })
    },
    onLoad: function (options) {
        var that = this

        console.log(options, "cxcccccccccccc")
        common.getLocalUserInfo(function (success, data) {
            if (success) {
                that.setData({
                    userInfo: data.user,
                    token: data.token,
                    username: data.user.realName,
                    cardNum: data.user.ids,
                    phone: data.user.phone,
                    userId: data.user.id,
                    adminCouponId: options.acId ? options.acId : '',
                    adminCouponNo: options.couponNo ? options.couponNo : '',
                    managerId: options.managerId ? options.managerId : '',
                    status: options.status ? options.status : '',
                    tengZhou: JSON.parse(options.tengZhou) ? JSON.parse(options.tengZhou) : [],
                    adminCouponNos: [options.couponNo]
                }, function () {
                    that.getCityList()
                    // that.getBank()
                    // console.log(this.data.adminCouponNos, "55566++65555")
                    if (that.data.username == null) {
                        common.showLoginPage()
                    }
                    this.storeList() //门店列表
                    // 7改
                    if (that.data.status == 7) {
                        this.getCoup()

                    }


                })
            } else {
                common.showLoginPage()
            }
        })
        let provice = []
        let cit = [this.data.city.city[0].children[0].label]

        for (let i = 0; i < this.data.city.city.length; i++) {
            provice.push(this.data.city.city[i].label)
        }
        this.setData({
            provice
        }, () => {
            this.setData({
                multiArray: [this.data.provice, cit]
            })
        })
    },
    // 城市列表
    getCityList() {
        common.post('/region/getCitys', {}, (res) => {
            if (res.status === 200) {
                this.setData({
                    cityss: res.data
                }, () => {
                    this.initPickerData() //日期三联动
                })
            } else {

            }
        })
    },
    fun_date(aa) {

        var Servetimes = this.data.nowTime //后台给的服务器当前时间
        console.log(Servetimes, "cehsi ")
        var date1 = new Date(Servetimes),
            time1 = date1.getFullYear() + "-" + (date1.getMonth() + 1) + "-" + date1.getDate(); //time1表示当前时间
        var date2 = new Date(date1);
        date2.setDate(date1.getDate() + aa);
        var time2 = date2.getFullYear() + "-" + (date2.getMonth() + 1) + "-" + date2.getDate();
        console.log(time1, "5555555")

        var obj = {
            Servetimes,
            startTime: time1,
            endTime: time2
        }
        return obj;
    },
    // 购买门店
    storeFn() {
        var storeList = []
        var storeListwo = []
        for (var i = 0; i < this.data.arrTwo.length; i++) {
            storeList.push(this.data.arrTwo[i].name)

        }
        this.setData({
            storeList,
        })

    },
    //选择门店
    bindStore(e) {
        let that = this
        var index = e.detail.value
        this.setData({
            indexs: index
        }, () => {
            that.setData({
                storeText: this.data.arrTwo[this.data.indexs].name,
            })
        })
    },
    getCoup() {
        var that = this
        var url = '/cityDisCoupon/getTZAreaFlag'
        var params = {
            managerId: this.data.managerId,
            userId: this.data.userId

        }
        common.post(url, params, function (res) {
            that.setData({
                nowTime: res.data.currentTime,
                isShowCity: res.data.flag
            }, () => {
                var time2 = that.fun_date(-8)
                console.log(time2, "结束时间")
                that.setData({
                    // startDate: time2.endTime,
                    // endDate: time2.startTime
                    startDate: '2000-10-1',
                    endDate: time2.endTime,
                    Servetimes: time2.Servetimes
                }, () => {
                    that.getCheckCoupon()
                    // that.getCityList()
                })
            })
        })

    },
    //等于7的时候被拒绝
    getCheckCoupon() {
        var that = this
        var url = '/cityDisCoupon/getCheckCoupon'
        var params = {
            adminCouponId: this.data.adminCouponId,
            userId: this.data.userId,
            adminCouponNo: this.data.adminCouponNo,
        }
        common.post(url, params, function (res) {
            console.log(res)
            if (res.status === 200) {
                // 门店
                var storeid = res.data.storeId
                var items = that.data.arrTwo.findIndex((item, index) => {
                    return item.id == storeid
                })
                var storeText = that.data.arrTwo[items].name

                //以旧换新凭证 
                var arr = []
                if (res.data.oldToNew == 1) {
                    arr = []
                } else {
                    arr = [{
                        url: res.data.oldToNewUrl,
                        deletable: true,
                    }]
                }
                // 匹配省
                var provice = that.data.proviceArray[0].find((item, index) => {
                    return item.value == res.data.regionStateId
                })
                // console.log(that.data.proviceArray[0])
                var proviceIndex = that.data.proviceArray[0].findIndex((item, index) => {
                    return item.value == res.data.regionStateId
                })

                // res.data.buyTime
                // console.log(res.data.buyTime , 11111)   //编辑返回的时间
                // console.log(that.data.Servetimes , 22222)  //服务器当前时间
                // 服务器当前的时间-8天，和编辑返回的时间作比较。大于就是错误时间
                // 1000 * 60 * 60 * 24 * 7
                // console.log((1000 * 60 * 60 * 24 * 7) , 22222)  //服务器当前时间
                // console.log(that.data.Servetimes - (1000 * 60 * 60 * 24 * 8) , '7天前的时间戳')  //服务器当前时间
                var eightDays = that.data.Servetimes - (1000 * 60 * 60 * 24 * 8)
                var date1 = new Date(eightDays),
                    time1 = date1.getFullYear() + "-" + (date1.getMonth() + 1) + "-" + date1.getDate(); //time1表示当前时间


                let shopPayList,
                    shopPayListThree,

                    feiPayOne = []
                let shopPayListOther = []


                res.data.payimagesList.map((item, i) => {
                    feiPayOne.push(item.imageUrl)
                })

                if (res.data.payimagesList.length >= 2) {
                    shopPayList = [{
                        url: res.data.payimagesList[1].imageUrl,
                        deletable: true,
                    }]

                }
                if (res.data.payimagesList.length >= 3) {
                    shopPayListThree = [{
                        url: res.data.payimagesList[2].imageUrl,
                        deletable: true,
                    }]

                    that.setData({
                        ffff: true
                    })
                }
                if (res.data.payimagesList.length >= 4) {
                    for (let i = 0; i < res.data.payimagesList.length; i++) {
                        if (i > 2) {
                            console.log("llllllllllllllllllllllllllllll")
                            shopPayListOther.push({
                                url: res.data.payimagesList[i].imageUrl,
                                deletable: true,
                            })
                        }
                    }
                }

                console.log(shopPayListOther, "shopPayListThreeshopPayListThree")

                that.setData({
                    noDuesPrice: res.data.noDuesPrice ? res.data.noDuesPrice : '',
                    invoiceCode: res.data.invoiceCode ? res.data.invoiceCode : '',
                    checkCode: res.data.checkCode ? res.data.checkCode : '',
                    radio: res.data.invoiceType.toString(), //0专 ，1普
                    proviceItem: provice,
                    // regionDistrictId: res.data.regionDistrictId,
                    regionCityId: res.data.regionCityId,
                    // regionStateId: res.data.regionStateId,
                    fyDenialReason: res.data.fyDenialReason,
                    indexs: items, //门店
                    storeText: storeText,
                    date: common.dateFormat('yyyy-MM-dd', res.data.buyTime), //开票日期
                    productText: res.data.product, //产品
                    receiverAddress: res.data.receiverAddress, //详细地址
                    invoiceNo: res.data.invoiceNo, //发票号
                    invoicePrice: res.data.invoicePrice, //发票金额
                    accountsBank: res.data.userBankName,
                    bankCode: res.data.userBankCode,
                    bankAccount: res.data.userBankNo,
                    fileList: [{
                        url: res.data.invoiceUrl,
                        deletable: true,
                    }], //发票照片
                    fileListtwo: [{
                        url: res.data.payimagesList[0].imageUrl,
                        deletable: true,

                    }],
                    shopPayListOther, //其他
                    shopPayList, //支付凭证第二张
                    shopPayListThree,//支付凭证第三张

                    feiPayOne,

                    identityCardFrontList: [{
                        url: res.data.idcardFrontPic,
                        deletable: true,
                    }],
                    identityCardBackList: [{
                        url: res.data.idcardBackPic,
                        deletable: true,
                    }],
                    drivingLicenseListzhu: [{
                        url: res.data.driveLicensePic,
                        deletable: true,
                    }],
                    drivingLicenseListfu: [{
                        url: res.data.driveLicensePicSubpage,
                        deletable: true,
                    }],
                    drivingLicenseListDeng: [{
                        url: res.data.motorRegistrationPic,
                        deletable: true,
                    }],
                    // oldToNew: !res.data.oldToNew ? true : false, // oldToNew 1否  是否以旧换新
                    fileListthree: arr, //以旧换新凭证
                    // areaFlag: !res.data.areaFlag ? true : false //是否是在地区门店内
                })

                // 编辑返回时间 - 当前时间-8天作比较
                if (res.data.buyTime - eightDays >= 0) { //返回的时间戳作比较
                    that.setData({
                        date: ''
                    })
                }

            } else {
                common.showRequestErrMsg(res)
            }
        })
    },
    cityselect(index, id) {
        var that = this
        for (let j = 0; j < this.data.list[index].children.length; j++) { //城市
            this.data.proviceArray[1].push({
                cityname: this.data.list[index].children[j].label,
                value: this.data.list[index].children[j].value
            })
        }
        // 城市
        var city = that.data.proviceArray[1].find((item, index) => {
            return item.value == id
        })
        var cityIndex = that.data.proviceArray[1].findIndex((item, index) => {
            return item.value == id
        })
        that.setData({
            cityItem: city,
            pindex: index,
            cIndex: cityIndex
        }, () => {
            that.regionSect(that.data.pindex, that.data.cIndex) //1.省 2.城市 3.县级id
        })
    },
    // 县区
    regionSect(index, cityIndex) {
        var that = this
        for (let k = 0; k < this.data.list[index].children[cityIndex].children.length; k++) { //区
            that.data.proviceArray[2].push({
                regionname: that.data.list[index].children[cityIndex].children[k].label,
                value: that.data.list[index].children[cityIndex].children[k].value
            })
            var region = that.data.proviceArray[2].find((item, index) => {
                return item.value == that.data.regionDistrictId
            })
        }
        that.setData({
            placeText: that.data.proviceItem.provicename + '-' + that.data.cityItem.cityname + '-' + region.regionname
        })
    }
})